package com.qf.bootdaily.controller;


import com.qf.bootdaily.entity.User;
import com.qf.bootdaily.service.UserService;
import com.qf.bootdaily.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    //添加用户
    @PostMapping("/insert")
    public Response<User> insert(User user){
        System.out.println(user);
        int i = userService.insertSelective(user);
        if (i>0){
            return Response.success();
        }else {
            return Response.fail();
        }
    }

    //查全部,用于注册判断
    @GetMapping("/userAll")
    public Response<List<User>> showAll(){
        List<User> users = userService.showAll();
        return Response.success(users);
    }
}
